package xkp.lesson.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Pointcut;

import java.util.Arrays;

public class Log {
    //
    //        <aop:pointcut id="expre1" expression="execution(* xkp.lesson..*.*(..))"/>



    public void beforeMethod(JoinPoint joinPoint){
       /* System.out.println(joinPoint.getSignature().getName());
        //System.out.println(joinPoint.getArgs());
        Object[] args = joinPoint.getArgs();
        System.out.println(Arrays.toString(args));*/
        System.out.println("方法执行前....");
    }

    public void beforeMethod2(JoinPoint joinPoint){
       /* System.out.println(joinPoint.getSignature().getName());
        //System.out.println(joinPoint.getArgs());
        Object[] args = joinPoint.getArgs();
        System.out.println(Arrays.toString(args));*/
        System.out.println("方法执行前2....");
    }


    public void afterMethod(JoinPoint point){
        System.out.println("方法执行后...");
    }

    public void afterRetuen(JoinPoint point,Object returnValue){
        System.out.println("获取方法的返回值");
        System.out.println(returnValue);
    }

    public void afterThrow(JoinPoint joinPoint,Exception ex){
        System.out.println("异常通知");
        System.out.println(ex.getMessage());
    }

    public void around(ProceedingJoinPoint joinPoint){
        System.out.println("前置通知");
        try {
            Object returnValue =  joinPoint.proceed();
            System.out.println("返回通知:"+returnValue);

        } catch (Throwable throwable) {
            System.out.println("异常通知");
            throwable.printStackTrace();
        }finally {
            System.out.println("最终通知");
        }
    }
}
